package app.jfinal;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * JFinal Record模式
 * 优势：无需事先建立任何模型的映射关系，更为简洁
 * 缺点：数据库表重构时，CRD功能可能需要分散多处的代码修改
 * Created by shadowedge on 2020/2/13.
 */
public class CityRecord{
    private static final Logger logger = LoggerFactory.getLogger(CityRecord.class);

    /**
     * 与Mapping模式的主要区别：
     * 入参为统一的Record类型
     * 持久化时需要指定表名
     * @param city
     */
    public static void add(Record city){
        Db.save("city",city); //主动映射
    }

    public static Record findByState(String state){
        return Db.findFirst("select * from city where state = ?",state);
    }

}
